package com.newbee.db;

import org.apache.hadoop.mapred.lib.db.DBWritable;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Instance implements DBWritable {

    private Integer id;

    private String instanceContent;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getInstanceContent() {
        return instanceContent;
    }

    public void setInstanceContent(String instanceContent) {
        this.instanceContent = instanceContent;
    }

    @Override
    public void write(PreparedStatement preparedStatement) throws SQLException {
        System.out.println(this);
        preparedStatement.setInt(1, id);
        preparedStatement.setString(2, instanceContent);
    }

    @Override
    public void readFields(ResultSet resultSet) throws SQLException {
        System.out.println(this);
        id = resultSet.getInt(1);
        instanceContent = resultSet.getString(2);
    }

    @Override
    public String toString() {
        return "Instance{" +
                "id=" + id +
                ", instanceContent='" + instanceContent + '\'' +
                '}';
    }
}
